home *** CD-ROM | disk | FTP | other *** search
- /* EasyCODE(C++) V5.1 02.03.1995 13:49:28 */
- /* EasyCODE O
- If=vertical
- LevelNumbers=no
- LineNumbers=no
- ScreenFont=Courier New,,80,9220,-11,0,400,0,0,0,0,0,0,3,2,1,49
- PrinterFont=Courier New,,80,17414,-34,0,400,0,0,0,0,0,0,3,2,1,49
- LastLevelId=383 */
-
- /* EasyCODE ( 1
- cobredoc.c */
-
- /* EasyCODE ( 371
- Includes, Constants */
- #include "convio.h"
- #include "conv.h"
- #include "tabledef.h"
- /* EasyCODE - */
- #define MAX_DELIMITERLEN 2
-
- #define USAGEMSG "Usage: %s inputfile outputfile\n"
-
- #define ERR_TEXT1 "Keyword expected "
- #define ERR_TEXT2 "Unexpected EOF "
- #define ERR_TEXT3 "Keyword is not a valid COBOL keyword "
- /* EasyCODE ) */
-
- /* EasyCODE ( 372
- StoreText */
-
- /* EasyCODE F */
- void StoreText(FILE* stream, BOOL comment, char* contents)
-
- // Writes text line to output file
- {
- if (comment)
- {
- // Only comments are written
- if ((*contents == '/')||(*contents == '*'))
- {
- StoreLine(inbuf,stream);
- }
- else
- {
- // Text line is no comment
- }
- }
- else
- {
- // comment == FALSE
- // Not only comment is written
- /* EasyCODE - */
- StoreLine(inbuf,stream);
- }
- }
- /* EasyCODE ) */
-
- /* EasyCODE ( 374
- main */
-
- /* EasyCODE F */
- void main(int argc, char *argv[])
-
- // Reads lines from the input file and writes them to the
- // output file. Empty lines are skipped. From each line
- // the keyword is extracted using GetKeyword() and the ID
- // is returned. If line is a text line it is checked whether
- // it is a comment line. If comment is not temporarily set
- // to FALSE only comments are written. Lines that are not
- // text lines are written unmodified.
- {
- int ID; /* ID of actual keyword */
- int lineNum = 0; /* Actual line number */
- char* contents; /* Content of actual line without */
- /* keyword+delimiter */
- char* delimiter; /* Delimiter of actual keyword */
- FILE* fdr; /* Input file */
- FILE* fdw; /* Output file */
- BOOL bEOF = FALSE; /* EOF indicator */
- BOOL comment = TRUE; /* indicate whether only comments */
- /* are written */
- /* EasyCODE - */
- /* Allocate memory for pointers */
- contents = malloc(I_BUFSIZE*sizeof(char));
- delimiter = malloc((MAX_DELIMITERLEN+1)*sizeof(char));
-
- /* Initialize pointers */
- *contents = '\0';
- *delimiter = '\0';
- if ((argc != 3))
- {
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- if (((*argv[1]=='/') || (*argv[1]=='-')) ||
- ((*argv[2]=='/') || (*argv[2]=='-')))
- {
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- if (strcmp(argv[1],argv[2])==0)
- {
- fprintf (stderr, USAGEMSG, argv[0]);
- exit(0);
- }
- fdr = OpenInput(argv[1]);
- fdw = OpenOutput(argv[2]);
- /* EasyCODE - */
- bEOF = ReadLine(inbuf,fdr);
- lineNum++;
- while (!bEOF)
- {
- ID = GetKeyword(delimiter, contents);
- switch (ID)
- {
- case ETF_EASYCODE:
- case ETF_SHORTINFO:
- case ETF_ENDSHORTINFO:
- case ETF_OPTIONS:
- case ETF_IFLAYOUT:
- case ETF_LEVELNUMBERS:
- case ETF_LINENUMBERS:
- case ETF_CONSTRUCTNUMBERS:
- case ETF_SCREENFONT:
- case ETF_PRINTERFONT:
- case ETF_LASTLEVELID:
- case ETF_ENDOPTIONS:
- case ETF_IF:
- case ETF_THEN:
- case ETF_ELSE:
- case ETF_ENDIF:
- case ETF_DUMMY:
- case ETF_PERFORMTESTBEFORE:
- case ETF_PERFORMTESTBEFOREBODY:
- case ETF_ENDPERFORMTESTBEFORE:
- case ETF_ONCONDITIONBRANCH:
- case ETF_ONCONDITIONBRANCHBODY:
- case ETF_ENDONCONDITIONBRANCH:
- case ETF_ONSELECTORBRANCH:
- case ETF_ONSELECTORBRANCHBODY:
- case ETF_ENDONSELECTORBRANCH:
- case ETF_TEXT:
- case ETF_ENDTEXT:
- StoreLine(inbuf,fdw);
- break;
- case ETF_LEVEL:
- // comment temporarily set to FALSE in
- // order to always write the level header
- /* EasyCODE - */
- comment = FALSE;
- /* EasyCODE - */
- StoreLine(inbuf,fdw);
- break;
- case ETF_LEVELBODY:
- comment = TRUE;
- /* EasyCODE - */
- StoreLine(inbuf,fdw);
- break;
- case ETF_ENDLEVEL:
- StoreLine(inbuf,fdw);
- break;
- case ETF_LINE:
- StoreText(fdw, comment, contents);
- break;
- case ETF_OFFSET:
- case ETF_PERFORMBEFOREVARYING:
- case ETF_PERFORMBEFOREVARYINGBODY:
- case ETF_ENDPERFORMBEFOREVARYING:
- case ETF_PERFORMTESTAFTER:
- case ETF_UNTIL:
- case ETF_ENDPERFORMTESTAFTER:
- StoreLine(inbuf,fdw);
- break;
- case ETF_PERFORMOUTLINE:
- // comment temporarily set to FALSE in
- // order to always write name
- /* EasyCODE - */
- comment = FALSE;
- /* EasyCODE - */
- StoreLine(inbuf,fdw);
- break;
- case ETF_ENDPERFORMOUTLINE:
- comment = TRUE;
- /* EasyCODE - */
- StoreLine(inbuf,fdw);
- break;
- case ETF_EXIT:
- case ETF_GOBACK:
- case ETF_COBPROGRAM:
- case ETF_IDDIV:
- case ETF_ENVIRONMENTDIV:
- case ETF_DATADIV:
- StoreLine(inbuf,fdw);
- break;
- case ETF_PROCDIVPARAM:
- // comment temporarily set to FALSE in
- // order to always write parameters
- /* EasyCODE - */
- comment = FALSE;
- /* EasyCODE - */
- StoreLine(inbuf,fdw);
- break;
- case ETF_PROCDIVBODY:
- comment = TRUE;
- /* EasyCODE - */
- StoreLine(inbuf,fdw);
- break;
- case ETF_ENDCOBPROGRAM:
- StoreLine(inbuf,fdw);
- break;
- case ETF_SECTION:
- // comment temporarily set to FALSE in
- // order to always write the section name
- /* EasyCODE - */
- comment = FALSE;
- /* EasyCODE - */
- StoreLine(inbuf,fdw);
- break;
- case ETF_SECTIONBODY:
- comment = TRUE;
- /* EasyCODE - */
- StoreLine(inbuf,fdw);
- break;
- case ETF_ENDSECTION:
- StoreLine(inbuf,fdw);
- break;
- case ETF_PARAGRAPH:
- // comment temporarily set to FALSE in
- // order to always write the paragraph name
- /* EasyCODE - */
- comment = FALSE;
- /* EasyCODE - */
- StoreLine(inbuf,fdw);
- break;
- case ETF_PARAGRAPHBODY:
- comment = TRUE;
- /* EasyCODE - */
- StoreLine(inbuf,fdw);
- break;
- case ETF_ENDPARAGRAPH:
- case ETF_PERFORMINLINE:
- case ETF_ENDPERFORMINLINE:
- case ETF_PERFORMTIMES:
- case ETF_PERFORMTIMESBODY:
- case ETF_ENDPERFORMTIMES:
- case ETF_PERFORMAFTERVARYING:
- case ETF_VARYING:
- case ETF_ENDPERFORMAFTERVARYING:
- case ETF_EXITPERFORM:
- case ETF_EXITTOTEST:
- case ETF_EXITPROGRAM:
- StoreLine(inbuf,fdw);
- break;
- case ETF_EXTERNALCALL:
- // comment temporarily set to FALSE in
- // order to always write name and parameters
- /* EasyCODE - */
- comment = FALSE;
- /* EasyCODE - */
- StoreLine(inbuf,fdw);
- break;
- case ETF_EXTERNALCALLPARAM:
- StoreLine(inbuf,fdw);
- break;
- case ETF_ENDEXTERNALCALL:
- comment = TRUE;
- /* EasyCODE - */
- StoreLine(inbuf,fdw);
- break;
- case ETF_SEARCH:
- case ETF_ATEND:
- case ETF_SEARCHBODY:
- case ETF_ENDSEARCH:
- StoreLine(inbuf,fdw);
- break;
- case ETF_ENTRY:
- // comment temporarily set to FALSE in
- // order to always write the name and parameters
- /* EasyCODE - */
- comment = FALSE;
- /* EasyCODE - */
- StoreLine(inbuf,fdw);
- break;
- case ETF_ENTRYUSING:
- StoreLine(inbuf,fdw);
- break;
- case ETF_ENDENTRY:
- comment = TRUE;
- /* EasyCODE - */
- StoreLine(inbuf,fdw);
- break;
- case ETF_EXCEPTION:
- // comment temporarily set to FALSE in
- // order to always write the exception
- /* EasyCODE - */
- comment = FALSE;
- /* EasyCODE - */
- StoreLine(inbuf,fdw);
- break;
- case ETF_ONEXCEPTION:
- comment = TRUE;
- /* EasyCODE - */
- StoreLine(inbuf,fdw);
- break;
- case ETF_EXCEPTIONBODY:
- case ETF_NOTEXCEPTIONBODY:
- case ETF_ENDEXCEPTION:
- case ETF_EVALUATE:
- case ETF_EVALUATEBODY:
- case ETF_EVALUATEOTHER:
- case ETF_ENDEVALUATE:
- StoreLine(inbuf,fdw);
- break;
- case NO_KEYWORD:
- // Skip empty line
- break;
- case ERROR_KEYWORD:
- err_msg(lineNum,ERR_TEXT1);
- /* EasyCODE - */
- exit(1);
- case EOF_KEYWORD:
- err_msg(lineNum,ERR_TEXT2);
- /* EasyCODE - */
- exit(1);
- default:
- err_msg(lineNum,ERR_TEXT3);
- /* EasyCODE - */
- exit(1);
- }
- bEOF = ReadLine(inbuf,fdr);
- lineNum++;
- }
- CloseFile(fdr);
- CloseFile(fdw);
- }
- /* EasyCODE ) */
- /* EasyCODE ) */
-